package com.tsh.erp.model;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import kiven.jee.model.StringIdObject;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "tbsys01userinfo")
//@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends StringIdObject {
	private static final long serialVersionUID = -3477243089352722830L;
	private String userid; // 用户帐号, （唯一，非空）
	private String username;// 用户名
	private String password; // 密码 （非空）
	private int sortorder;// 排序
	private String phone;// 办公电话
	private String mobile;// 移动电话
	private String email;// 电子邮件（ 唯一）
	private String enabled;// 是否可用
	private int passworderrcnt;// 登录失败尝试次数
	private int accountlocked;// 账号是否锁定
	private Date accountlockeddate;// 账号锁定日期
	private String loginip;// 登录IP地址
	private Date logindate;// 登录时间
	private String lastloginip;// 最后一次登录IP
	private Date lastlogindate;// 最后一次登录时间
	private String creator;// 创建人
	private Date createdate;// 创建日期
	private String modifier;// 修改人
	private Date modifydate;// 修改日期
	private String createip;// 创建机器IP
	private String desn;// 描述信息
//	private Date passwordupdate;// 密码修改日期
//	private Department department;// 所在的部门
//	private Set<Role> roles = new LinkedHashSet<Role>(); // 有序的关联对象集合

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getSortorder() {
		return sortorder;
	}

	public void setSortorder(int sortorder) {
		this.sortorder = sortorder;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEnabled() {
		return enabled;
	}

	public void setEnabled(String enabled) {
		this.enabled = enabled;
	}

	
	public int getPassworderrcnt() {
		return passworderrcnt;
	}

	public void setPassworderrcnt(int passworderrcnt) {
		this.passworderrcnt = passworderrcnt;
	}

	public int getAccountlocked() {
		return accountlocked;
	}

	public void setAccountlocked(int accountlocked) {
		this.accountlocked = accountlocked;
	}

	public Date getAccountlockeddate() {
		return accountlockeddate;
	}

	public void setAccountlockeddate(Date accountlockeddate) {
		this.accountlockeddate = accountlockeddate;
	}

	public String getLoginip() {
		return loginip;
	}

	public void setLoginip(String loginip) {
		this.loginip = loginip;
	}

	public Date getLogindate() {
		return logindate;
	}

	public void setLogindate(Date logindate) {
		this.logindate = logindate;
	}

	public String getLastloginip() {
		return lastloginip;
	}

	public void setLastloginip(String lastloginip) {
		this.lastloginip = lastloginip;
	}

	public Date getLastlogindate() {
		return lastlogindate;
	}

	public void setLastlogindate(Date lastlogindate) {
		this.lastlogindate = lastlogindate;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	public Date getModifydate() {
		return modifydate;
	}

	public void setModifydate(Date modifydate) {
		this.modifydate = modifydate;
	}

	public String getCreateip() {
		return createip;
	}

	public void setCreateip(String createip) {
		this.createip = createip;
	}

	/*public Date getPasswordupdate() {
		return passwordupdate;
	}

	public void setPasswordupdate(Date passwordupdate) {
		this.passwordupdate = passwordupdate;
	}*/

	public String getDesn() {
		return desn;
	}

	public void setDesn(String desn) {
		this.desn = desn;
	}

	/*@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}
	
	// 避免定义CascadeType.REMOVE, 否则删除角色时会连带删除拥有它的用户
	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	// 多对多定义
	@JoinTable(name = "ZHJY_SYS_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	// Fecth定义
	@Fetch(FetchMode.SUBSELECT)
	// 集合按id排序
	@OrderBy("id")
	
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}*/
}
